/*
    //自定义时间
    var s1 = 20;
    var f1 = 5;
    var m1 = 59;


    var t = setInterval(function(){

        var sz = document.querySelector("#s");
        var fz = document.querySelector("#f");
        var mz = document.querySelector("#m");


//获取当前时间
        var time = new Date();

//获取当前时
        var s = time.getHours();

//获取当前分
        var f = time.getMinutes();

//获取当前秒
        var m = time.getSeconds();


//计算时间差

        document.querySelector("#s").innerHTML = s1 - s;
        document.querySelector("#f").innerHTML = f1 - f;
        document.querySelector("#m").innerHTML = m1 - m;


//倒计时结束
        if (fz.innerHTML < 0 || mz.innerHTML < 0){
            clearInterval(t);
            alert("倒计时结束");
            fz.innerHTML = 0;
            mz.innerHTML = 0;
        }

    });
*/






/*
var t =setInterval(function(){

    //获取当前时间
    var time = new Date();

    //设定时间
    var sd = new Date("2019-9-5 15:35:52");

    //时间差
    var sc = sd.getTime()-time.getTime();

    //小时取余
    var xs = sc / (1000 * 3600);

    //分钟取余
    var fz = sc / (1000 * 60) % 60;

    //秒数取余
    var ms = sc / (1000) % 60;

    //时分秒各取整数
    xs = Math.floor(xs);
    fz = Math.floor(fz);
    ms = Math.floor(ms);

    if (xs < 10){
        xs = "0" + xs;
    }
    if (fz < 10){
        fz = "0" + fz;
    }
    if (ms < 10){
        ms = "0" + ms;
    }

    document.querySelector("#s").innerHTML = xs;
    document.querySelector("#f").innerHTML = fz;
    document.querySelector("#m").innerHTML = ms;

    if (ms == 0){
        clearInterval(t);
    }

});
*/


function wn(){

    //设定结束时间
    var sd = new Date('2019-9-6 20:00:00');

//获取当前时间
    var dx = new Date();

//计算时间差
    var sc = sd.getTime() - dx.getTime();

//相差的描述
    var sc = sc / 1000;

    //设置当前的时分秒
    var xs = 0;
    var fz = 0;
    var ms = 0;


//时差取整
    var qz = parseInt(sc);

if(sc >= 0){

    //根据剩余秒数算出小时
    var xs = parseInt(qz / 3600);

//根据剩余秒数算出分钟
    var fz = parseInt((qz / 60) % 60 );

//根据剩余秒数算出秒数
    var ms = parseInt(qz % 60);

//当时分秒小于10的时候，在前面加一个0；

    if(xs < 10){
        xs = "0" + xs;
    }
    if(fz < 10){
        fz = "0" + fz;
    }
    if(ms < 10){
        ms = "0" + ms;
    }

}else {
    clearInterval(t);
}

//把时分秒放入相应的位置

    document.querySelector("#s").innerHTML = xs;
    document.querySelector("#f").innerHTML = fz;
    document.querySelector("#m").innerHTML = ms;


}

//执行一次函数

wn();

var t = setInterval(function(){

    wn();

});

























